|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00016 #include "Compile_Options.h" 00017 #include "derivative.h" 00018 //#include "utils.h" /* For Copy Array */ 00019 #include "PIT.h" 00020 /* 00021 ****************************************************************************** 00022 * constants 00023 ****************************************************************************** 00024 */ 00025 /* 00026 ****************************************************************************** 00027 * Globals 00028 ****************************************************************************** 00029 */ 00030 /* 00031 ****************************************************************************** 00032 * u8fnPITConfig 00033 ****************************************************************************** 00034 */ 00035 uint8_t u8fnPITConfig(const uint8_t u8Channel, 00036 const uint32_t u32InitialCount, 00037 const uint8_t u8UseISR) 00038 { 00039 /* Local variables */ 00040 uint8_t u8Status; 00041 00042 u8Status = CLEAR; 00043 00044 /* Make sure that the module is enabled before any configuration is done */ 00045 PIT.PITMCR.B.MDIS = CLEAR; 00046 00047 /* Also, make sure that the particular channel exists */ 00048 if(N_PIT_CHANNELS > u8Channel) 00049 { 00050 /* Make sure that the particular channel we're configuring is off */ 00051 PIT.CH[u8Channel].TCTRL.B.TEN = CLEAR; 00052 00053 /* Load the number of counts before the timer expires - we are always */ 00054 /* using the system clock. */ 00055 PIT.CH[u8Channel].LDVAL.R = u32InitialCount; 00056 00057 /* Clear any pending flags */ 00058 PIT.CH[u8Channel].TFLG.R = TRUE; 00059 00060 /* Set interrupts */ 00061 PIT.CH[u8Channel].TCTRL.B.TIE = (CLEAR < u8UseISR); 00062 } 00063 else 00064 { 00065 /* Not a valid channel */ 00066 u8Status = PIT_INVALID_CH; 00067 } 00068 00069 return(u8Status); 00070 } 00071 /* 00072 ****************************************************************************** 00073 * vfnPITStart 00074 ****************************************************************************** 00075 */ 00076 void vfnPITStart(const uint8_t u8Channel, const uint8_t u8Enable) 00077 { 00078 PIT.CH[u8Channel].TCTRL.B.TEN = (CLEAR < u8Enable); 00079 return; 00080 } 00081 /* 00082 ****************************************************************************** 00083 * u8fnPITWaitByPoll 00084 ****************************************************************************** 00085 */ 00086 uint8_t u8fnPITWaitByPoll(const uint8_t u8Channel, const uint8_t u8Restart) 00087 { 00088 /* Locals */ 00089 uint8_t u8Status; 00090 uint32_t u32TimeOut; 00091 00092 /* Init */ 00093 u8Status = CLEAR; 00094 u32TimeOut = PIT.CH[u8Channel].LDVAL.R; 00095 00096 /* Wait for it */ 00097 do 00098 { 00099 u32TimeOut--; 00100 }while((u32TimeOut != CLEAR) && (PIT.CH[u8Channel].TFLG.R == CLEAR)); 00101 00102 if(CLEAR == u32TimeOut) 00103 { 00104 /* We timed-out. Not good */ 00105 u8Status = PIT_ERROR_TIMED_OUT; 00106 } 00107 else 00108 { 00109 /* It's probably a good idea to clear the flag */ 00110 PIT.CH[u8Channel].TFLG.B.TIF = TRUE; 00111 00112 /* And depending on the passed argument, restart the PIT */ 00113 if(CLEAR != u8Restart) 00114 { 00115 /* PIT already counting down again */ 00116 } 00117 else 00118 { 00119 vfnPITStart(u8Channel, CLEAR); 00120 } 00121 } 00122 00123 return(u8Status); 00124 } 00125 00126 /* 00127 ****************************************************************************** 00128 * 00129 * End of file. 00130 * 00131 ****************************************************************************** 00132 */